<template>
	<div>
		
		<van-cell-group>
			<van-field v-model="username" required clearable label="用户名" placeholder="请输入用户名" ref="user"/>

			<van-field v-model="password" type="password" label="密码" placeholder="请输入密码" required  ref='pass'/>
		</van-cell-group>

		<van-button type="primary" @click="login(username,password)">登录</van-button>
		<van-button type="info" to='/register'>注册</van-button>

	</div>

</template>

<script>
	import {mapActions} from 'vuex'
	import axios from 'axios'
	import Head from '@/components/Head'
	export default {
		name: "Login",
		data() {
			return {
				username: "",
				password: "",
				title:'登录'
			}
		},
		components: {
			Head
		},
		mounted(){
			this.$emit('toTitle',this.title)
		},
		methods:{
			// ...mapActions(['login'])
			
			login(){
				var username =  this.$refs.user.value
				var password =this.$refs.pass.value
				var that=this
				axios({
					url:'http://10.8.158.36:8080/UserLogin.do',
					// url:'http://jx.xuzhixiang.top/ap/api/login.php',
					params:{username, password}
				
				}).then((res)=>{
					console.log(res)
					if(res.data.code==0){
						this.$store.state.username=res.data.data;
						
						// alert(res.data.msg)
						localStorage.setItem('token',res.data.data)
						// localStorage.setItem('username',res.data.data)
						this.$router.push('/home')
						
					}
				})
			}
				
			
		}
	}
</script>

<style>
</style>
